<#escape x as x?html>

<SCRIPT type="text/javascript">


var orgMultiSelectSetting = {
		expandAll:true,
		check: {
			enable: true,
			chkStyle: "checkbox",
			//chkboxType:  { "Y" : "", "N" : "" }
			chkboxType: { "Y" : "", "N" : "" }
		},
		data : {
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey : "pid",
				rootPId : "null"
			}
		}
	};
	

var orgMultiSelectTree;
function showZtreeOrg(){
	
	if(!orgMultiSelectTree){
		jQuery.post("${ctx}/system/org/list/json",
				function(_json) {
					if (_json.status == "success") {
						$.fn.zTree.init($("#orgMultiSelectTree"), orgMultiSelectSetting,_json.data);
						 orgMultiSelectTree =$.fn.zTree.getZTreeObj("orgMultiSelectTree");
						//zTree.expandAll(true);
						checkedZtreeNodes(jQuery("#orgIds").val(),"orgMultiSelectTree");
					} else {
						myalert(_json.message);
						return false;
					}
				});
		
	}else{
		checkedZtreeNodes(jQuery("#orgIds").val(),"orgMultiSelectTree");
	}
	
	
	
	//页面层-自定义
	layer.open({
	  shadeClose:true,
	  type: 1,
	  title: "选择部门",
	  skin: 'layui-layer-rim', //加上边框
	  area: ['600px', '400px'], //宽高
	  content: $("#div_orgMultiSelectTree"),
	  closeBtn: 1,
	  btn: ['确定'], //按钮
	  yes:function(index, layero){
		    selectZtreeOrg();
		    layer.close(index); //如果设定了yes回调，需进行手工关闭
		  }
	});
	
	
	return false;
	
	
}



function selectZtreeOrg(){
	
	var nodes = orgMultiSelectTree.getCheckedNodes(true);
	
	var orgNames="";
	var orgIds="";
	
	jQuery(nodes).each(function(i,obj){
		orgNames=orgNames+obj.name+",";
		orgIds=orgIds+obj.id+",";
	});
	jQuery("#orgNames").val(orgNames);
	jQuery("#orgIds").val(orgIds);
	
	
}
	
	
	
	
	

jQuery(document).ready(function(){
	
	//回选 下拉框
	jQuery("#search_state option[value='${(returnDatas.queryBean.state)!'是'}']").prop("selected",true);
	
	
	
	//加载角色
	jQuery.ajax({
		url : ctx+"/system/role/list/json",
		type : "post",
		dataType : "json",
		success : function(_json) {
			if(_json.status=="error"){
				return;
			}
			
			jQuery(_json.data).each(function(i,_obj){
				jQuery("#roleIds").append("<option value='"+_obj.id+"'>"+_obj.name+"</option>");
			});
			
			jQuery("#roleIds").select2();
		}
	});
	
	
	
	
	
	
	
	
	$(".sub_left_menu tbody tr").click(function() {
		$("#pwdDiv").hide();
		$(".sub_left_menu tbody tr").removeClass("active");
		$(this).attr("class", "active");
		var _url=ctx + "/system/user/look/json?id="+ $(this).attr("id");
	
		jQuery.ajax({
			url : _url,
			type : "post",
			dataType : "json",
			success : function(_json) {
				if(_json.status=="success"){
					showdata(_json);
				}
			}
		});
		return false;
	})
	
});






function deleteUser(){
	var id=jQuery("#id").val();
	if(!id||id==""){
		myalert("请选择你要删除的记录");
		return;
	}else{
		var _url="${ctx}/system/user/delete?id="+id;
		var listurl="${ctx}/system/user/list";
		
		mydelete(_url,listurl,{},"确定删除用户?");
	}
}

function showdata(result) {
	$("#btn_add").hide();
	$("#btn_reload").show();
	$("#btn_update").show();
	$("#btn_delete").show();
	
	
	
	for (var s in result.data) {
		set_val(s, result.data[s]);
	}
	jQuery("#account").prop("readonly",true);
	

	//回选 下拉框
	jQuery("#state option[value='"+result.data['state']+"']").prop("selected",true);
	  
	  jQuery("#password").val("");
	
	  $("#roleIds").find("option:selected").prop("selected",false);
	  jQuery(result.data["userRoles"]).each(function(i,_obj){
			jQuery("#roleIds option[value='"+_obj.id+"']").prop("selected",true);
	  });
	  jQuery("#roleIds").trigger("change");
	  
	  
	    var orgNames="";
		var orgIds="";
		
	  jQuery(result.data["userOrgs"]).each(function(i,obj){
		  orgNames=orgNames+obj.name+",";
			orgIds=orgIds+obj.id+",";
		});
		jQuery("#orgNames").val(orgNames);
		jQuery("#orgIds").val(orgIds);
	 
	  
	  

}

function check(type){

	if(type=="1"){
		var password = $('#password').val();
		if(password==null||password==""){
			myinfo("请填写密码!");
			return;
		}	
		//密码长度
		if(password.length<6){
			myinfo("密码长度不能少于6位!");
			return false;
		}
	}
	



	
	var mobile=$("#mobile").val();
	if(mobile!="" && mobile!=null){
		 var reg = /^1\d{10}$/;
		 if(!reg.test(mobile)){
			 myinfo("手机号格式错误!");
				return false;
		 }
	}
	

	var listurl='${ctx}/system/user/list';
	
	
	commonUpdateForm("updateForm",listurl);
}

</SCRIPT>







<div class="operate panel panel-default" style="height:65px;">
	<div class="panel-body">
		<div class="pull-left">
<form class="form-horizontal" method="post"  action="${ctx}/system/user/list"  name="searchForm"  id="searchForm" onkeydown="if(event.keyCode==13)return false;" >
	<input type="hidden" name="pageIndex" id="pageIndex" value="${(returnDatas.page.pageIndex)!'1'}" />
<input type="hidden" name="sort" id="page_sort" value="${(returnDatas.page.sort)!'desc'}"  />
<input type="hidden" name="order" id="page_order" value="${(returnDatas.page.order)!'id'}"  />
			<label for="search_account"><b>账号:</b></label> 
			 <input type="text" id="search_account"  name="account" placeholder="请填写账号"  value="${(returnDatas.queryBean.account)!''}">
			 <label for="search_state"><b>是否可用:</b></label> 
			 <select id="search_state"  name="state" >
													<option value="是">是</option>
													<option value="否">否</option>
			 </select>
			 
			 
			
			<a  href="javascript:mySubmitForm('searchForm');"
				class="btn btn-purple btn-sm">
					查询 <i class="ace-icon fa fa-search icon-on-right bigger-10"></i>
				</a>

</form>
		</div>
		
		
		
		<div class="pull-right">
			
			
			 <@shiro.hasPermission
			name="/system/user/update" >
			<a id="btn_reload" href="javascript:location.reload();"
				class="btn  btn-sm  btn-primary " style="display: none;" >
				跳转至新增 >>
			</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			
			
			<a id="btn_add" href="javascript:check('1');"
				class="btn  btn-sm  btn-primary ">
				<img src="${ctx}/images/btn_save.png" style="vertical-align: middle;" />保存新增
			</a>

			<a  id="btn_update" href="javascript:check('2');"
				class="btn  btn-sm  btn-primary " style="display: none;">
				<img src="${ctx}/images/btn_save.png" style="vertical-align: middle;" />保存修改
			</a>

			</@shiro.hasPermission>
			
 			 <@shiro.hasPermission name="/system/user/delete" > 
 			<a  id="btn_delete"  href="javascript:deleteUser();" class="btn btn-sm btn-danger " style="display: none;"> 
 				 删除
 			</a>
			</@shiro.hasPermission> 
			
		</div>
			
			
			
		</div>
	</div>



<!-- /.page-header -->



<div class="row">
	<div class="col-xs-12">
		<div class="row">
			<div class="col-xs-12">
				<div class="col-sm-4 sub_left_menu ">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="widget-title">账号列表</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<table  class="table table-striped table-bordered table-hover">
									<thead>
										<tr>
											<th>账号</th>
											<th>姓名</th>
											<th>手机号</th>
										
										</tr>
									</thead>
									<tbody>
									
								    <#if (returnDatas.data??)&&(returnDatas.data?size>0)>
									   <#list returnDatas.data as _data>
											<tr id="${(_data.id)!''}">
												<td>${(_data.account)!''}</td>
												<td>${(_data.name)!''}</td>
												<td>${(_data.mobile)!''}</td> 
											</tr>
				                         </#list>
									 </#if>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
				<div class="col-sm-8">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="widget-title">详细信息</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<form class="form-horizontal clearfix" method="post"  action="${ctx}/system/user/update"  name="updateForm" id="updateForm">
									<input type="hidden" id="id" name="id" value=""> 
									<input type="hidden" id="pname" name="pname" value="">
									
									<div class="col-sm-6">
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="account"> 账号<span  style="color:#E12424">*</span> </label>
										
											<div class="col-sm-9">
												<input type="text" id="account" name="account" placeholder="账号"  datatype="*1-200"  errormsg="账号长度1--200位之间!" nullmsg="账号不能为空"  class="form-control">
											</div>
										</div>
										<div class="form-group" id="pwdDiv">
											<label class="col-sm-3 control-label no-padding-right" for="password"> 密码 </label>
										
											<div class="col-sm-9">
												<input type="password" id="password" name="password"    placeholder="密码" class="form-control">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="name"> 姓名<span  style="color:#E12424">*</span> </label>
											<div class="col-sm-9">
												<input type="text" id="name" name="name" placeholder="姓名" datatype="*1-200"  errormsg="姓名长度1--200位之间!" nullmsg="姓名不能为空" class="form-control">
											</div>
										</div>
										
										
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="orgIds"> 部门<span  style="color:#E12424">*</span> </label>
											<div class="col-sm-9">
												<div class="input-group">
													<input name="orgNames" class="form-control val" id="orgNames" type="text" datatype="*"   nullmsg="角色不能为空"  readonly="readonly"/>
													<input name="orgIds"  id="orgIds" type="hidden"  />
													<span class="input-group-btn">
															<a onclick="showZtreeOrg();" class="btn btn-sm btn-primary">
																						<i class="fa fa-search"></i>
															</a>
													 </span>
												</div>
											</div>
										</div>
										
										
										
										
										
										
										
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="roleIds"> 角色<span  style="color:#E12424">*</span> </label>
											<div class="col-sm-9">
												<select  id="roleIds" name="roleIds"   class="form-control"  datatype="*"   nullmsg="角色不能为空"   multiple data-placeholder="请选择角色">
												</select>
											</div>
										</div>
										
									</div>
									<div class="col-sm-5">
										
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right no-padding-left" for="mobile"> 手机号</label>
											<div class="col-sm-9">
												<input type="text" id="mobile" name="mobile" placeholder="手机号" class="form-control">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right no-padding-left" for="email"> 电子邮箱 </label>
											<div class="col-sm-9">
												<input type="text" id="email" name="email" placeholder="电子邮箱" class="form-control">
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="sex"> 性别</label>
											<div class="col-sm-9">
												<select class="form-control " id="sex" name="sex">
														<option value="男">男</option>
														<option value="女">女</option>
												</select>
											</div>
										</div>
										
										
										
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right no-padding-left" for="state"> 是否可用</label>
											<div class="col-sm-9">
												<select id="state" name="state" class="form-control col-10">
													<option value="是">是</option>
													<option value="否">否</option>
												</select>
											</div>
										</div>

									</div>
									
								</form>
							</div>
						</div>
					</div>
					

				</div>



			</div>
			<!-- /.span -->

		</div>

		<#if returnDatas.page??> <@h.pagetoolbar page=returnDatas.page
		formId='searchForm' /> </#if>

	</div>
</div>


<!-- /.main-container -->
<div id="div_orgMultiSelectTree" >
	<ul id="orgMultiSelectTree" class="ztree"></ul>
</div>


</#escape>